﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EmoneyWeiXinCommon;
using EmoneyWeiXinEntity;
using EmoneyWeiXinThreadDAL;

namespace EmoneyWeiXinThreadBLL
{
    public class ThreadPolPicTuiSong
    {
        public static weixinUserDal dalWeixinuser = new weixinUserDal();
        public string tojson { get; set; }
        public string newsreportid { get; set; }
        public int weixinid { get; set; }
        public string token { get; set; }
        public int hisid { get; set; }
        public string toFormuser { get; set; }
        public ThreadPolPicTuiSong() { }
        public ThreadPolPicTuiSong(string Tojson, string Token, string toformuser, string Newsreportid, int Weixinid, int Hisid)
        {
            this.tojson = Tojson;
            this.token = Token;
            this.toFormuser = toformuser;
            this.newsreportid = Newsreportid;
            this.weixinid = Weixinid;
            this.hisid = Hisid;
        }

        public void ThreadProc(object sender)
        {
            weixinResult res = JsonTools.ToObject<weixinResult>(TokenHelper.RequestPost(Config.WeiXin_ApiUrl + "message/custom/send?access_token=" + token, tojson));
            if (res != null)
            {
                PropellingLogEntity pplogEntity = new PropellingLogEntity();
                pplogEntity.id = 0;
                pplogEntity.newsreportid = newsreportid;
                pplogEntity.weixinid = weixinid;
                pplogEntity.ToUsername = toFormuser;
                pplogEntity.errorResult = res.errcode;
                pplogEntity.updatetime = System.DateTime.Now;
                pplogEntity.hisid = hisid;
                dalWeixinuser.getPropellingUpdate(pplogEntity);
            }
        }
    }
}
